Skip to content

Fix LaTeX builder crash on tables with no body rows#14291

Open
veeceey wants to merge 1 commit intosphinx-doc:masterfrom
veeceey:fix/latex-empty-table-stopiteration
Open

Fix LaTeX builder crash on tables with no body rows#14291
veeceey wants to merge 1 commit intosphinx-doc:masterfrom
veeceey:fix/latex-empty-table-stopiteration

Conversation

@veeceey
Copy link

@veeceey veeceey commented Feb 10, 2026

Summary

Fixes #14271.

LaTeXFootnoteVisitor.depart_table() unconditionally calls next(node.findall(nodes.tbody)), which raises StopIteration when a table has header rows but no body rows. This happens when external parsers like myst_parser produce a docutils table node tree from Markdown tables that have only a header row (e.g. | Key | P | Summary |\n| --- | --- | --- |).

The fix:

  • Use next(..., None) to safely handle the missing tbody
  • When tbody is present, behavior is unchanged (footnotes are inserted at the head of tbody)
  • When tbody is absent, any collected table footnotes are placed after the table node instead, preserving footnote rendering

Test:

  • Added test_latex_table_empty_body which constructs a table node with thead but no tbody (mirroring what myst_parser produces) and verifies that LaTeXFootnoteVisitor processes it without raising StopIteration
  • Verified the test fails with StopIteration on the unfixed code and passes with the fix
  • All existing LaTeX builder tests continue to pass

Test plan

  • New unit test test_latex_table_empty_body passes
  • All existing LaTeX table tests pass (9/9)
  • All existing LaTeX footnote tests pass (5/5)
  • Full LaTeX test suite passes (82 passed, 11 skipped for missing LaTeX styles)
  • ruff check passes on both modified files

The LaTeXFootnoteVisitor.depart_table() method called
next(node.findall(nodes.tbody)) which raises StopIteration when a
table has header rows but no body rows (as produced by e.g. myst_parser
from Markdown). Handle the missing tbody gracefully by placing any
collected footnotes after the table node instead.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@veeceey
Copy link
Author

veeceey commented Feb 19, 2026

Friendly ping - any chance someone could take a look at this when they get a chance? Happy to make any changes if needed.

@veeceey veeceey force-pushed the fix/latex-empty-table-stopiteration branch from 795d52a to 6bbbc96 Compare February 24, 2026 07:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Error generating latex from Markdown with empty table

1 participant